//
// Created by ultcrt on 2021/5/22.
//
#include "data_processor.h"
#include "redis_io.h"
#include <nlohmann/json.hpp>
#include <iostream>
#include <unistd.h>

using namespace nlohmann;
using namespace std;

int main(int argc, char** argv) {
    string redis_url = argv[1];
    RedisIO redis_io((char*)redis_url.data());
    DataProcessor data_processor(argv[2]);
    vector<string> keys;
    keys.emplace_back("decision");
    keys.emplace_back("detect_inside");
    keys.emplace_back("vehicle_person_front");
    keys.emplace_back("vehicle_person_back");
    keys.emplace_back("road");

    while (true) {
        json fetched = redis_io.fetch(keys);
        json processed = data_processor.process(fetched);
        if (processed.empty()) continue;
        redis_io.push("overall_info", processed, 10);
        usleep(20000);
    }
}